home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: peer-news.britain.eu.net!warwick!pcl!news
- From: besec@wmin.ac.uk (Nicholas Arthur Llewellyn)
- Subject: Using BC4.5 TArrayAsVector of my class in a class!
- Message-ID: <DKMHJE.B0B@westminster.ac.uk>
- Sender: news@westminster.ac.uk
- Nntp-Posting-Host: dip-8.dialup
- Organization: University of Westminster
- X-Newsreader: Forte Free Agent 1.0.82
- Date: Wed, 3 Jan 1996 21:34:59 GMT
-
- This is my first use of BC4.5 and I'm trying to use the array class
- library to hold the class Card, in the class's Pack and Hand.
-
- I get the error:
-
- Compiling PROJECT.CPP:
-
- <This is the one I'm trying to fix>
- Error PROJECT.CPP 71: Cannot find default constructor to initialize
- member 'pack' in function Pack::Pack()
-
- <These other two I got from messing around trying to fix the above
- error>
- Error PROJECT.CPP 72: Type qualifier 'pack' must be a struct or class
- name in function Pack::Pack()
- Error PROJECT.CPP 72: Statement missing ; in function Pack::Pack()
-
- The Borland manuals are not much help, all the examples are too
- simple.
-
- Is there any one out there who can point in the correct direction?
-
- Here's the code:
-
- // Poker playing program v0.0
- // by N A Llewellyn
-
- #include <iostream.h>
- #include <classlib\arrays.h>
-
- // in order of rank from low to high
- enum RANK
- {two,three,four,five,six,seven,eight,nine,ten,jack,queen,king,ace};
-
- enum SUIT {clubs,harts,diamonds,spades}; // no order of rank
-
- enum FACE {up,down};
-
- class Card {
-
- private:
- RANK rank;
- SUIT suit;
- FACE face;
-
- friend ostream& operator << (ostream&,const Card&);
-
- public:
- Card() {rank=two;suit=clubs;face=down;}
- Card(const Card & c) {rank=c.rank;suit=c.suit;face=c.face;}
- int operator == (const Card & c) {return rank == c.rank;}
- int operator < (const Card & c) {return rank < c.rank;}
- void SetRank(RANK r) {rank=r;}
- void SetSuit(SUIT s) {suit=s;}
- void SetFace(FACE f) {face=f;}
- };
-
- typedef TSArrayAsVector <Card> CardArray;
- typedef TSArrayAsVectorIterator <Card> CardArrayIterator;
-
- class Pack {
-
- private:
- CardArray pack;
- unsigned int NumberOfCards;
-
- public:
- Pack();
- void AddCard(Card c) {pack.Add(c);NumberOfCards++;}
- void FindAndDetach(Card c) {pack.Detach(c);}
- void DetachFrom(int i) {pack.Detach(i);}
- void FlushPack(void) {pack.Flush();NumberOfCards=0;}
- int IsPackEmpty(void) {return pack.IsEmpty();}
- };
-
- class Hand {
-
- private:
- CardArray hand;
- unsigned int NumberOfCards;
-
- public:
- Hand();
- void AddCard(Card c) {hand.Add(c);NumberOfCards++;}
- void FindAndDetach(Card c) {hand.Detach(c);}
- void DetachFrom(int i) {hand.Detach(i);}
- void FlushPack(void) {hand.Flush();NumberOfCards=0;}
- int IsPackEmpty(void) {return hand.IsEmpty();}
- ~Hand();
- };
-
- ostream& operator << (ostream& os,const Card& c)
- {return os<<c.rank<<","<<c.suit<<","<<c.face;}
-
- // definition of constructor for Pack
-
- Pack::Pack()
- {
- Card card;
- SUIT suit;
- RANK rank;
-
- NumberOfCards=0;
-
- for(suit=clubs;suit<=spades;suit++)
- for(rank=two;rank<=ace;rank++)
- {
- card.SetSuit(suit);
- card.SetRank(rank);
- card.SetFace(down);
- AddCard(card);
- NumberOfCards++;
- }
- }
-
- void Show(Card& c,void*)
- {cout<<c<<endl;}
-
- void UseForEach(CardArray& c)
- {c.ForEach(Show,0);}
-
- int main()
- {
- Pack pack1;
- UseForEach(pack1.pack);
- return 0;
- }
-
-